package com.sxz.sbs.module.mine.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.mine.mode.AdminPhoneBean;
import com.sxz.sbs.module.mine.mode.UserInfo;
import com.sxz.sbs.module.mine.view.PersonageView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;


/**
 * 个人中心P层
 */

public class PersonagePresenter extends RxPresenter<PersonageView>{
    /**
     * 退出登录
     */
    public void loginOut (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().exitLogin(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView){
                    @Override
                    public void onNext(String token) {
                        mView.onLoginOutSuccess();
                    }
                })
        );
    }
    /**
     * 获取个人信息
     */
    public void getUserInfo (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getUserInfo(map)
                .compose(RxUtil.<UserInfo>handleResult())
                .subscribeWith(new RxSubscriber<UserInfo>(mView){
                    @Override
                    public void onNext(UserInfo info) {
                        mView.onGetUserInfoSuccess(info);
                    }
                })
        );
    }
    /**
     * 上传头像
     */
    public void uploadHead (MultipartBody.Part file) {
        addSubscribe(App.getInstance().getApi().uploadHead(file)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView){
                    @Override
                    public void onNext(String info) {
                        mView.onUploadHeadSuccess(info);
                    }
                })
        );
    }
    /**
     * 上传头像
     */
    public void getAdminPhone (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getAdminPhone(map)
                .compose(RxUtil.<List<AdminPhoneBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<AdminPhoneBean>>(mView){
                    @Override
                    public void onNext(List<AdminPhoneBean> info) {
                        mView.onGetAdminPhoneData(info);
                    }
                })
        );
    }
}
